package net.tinyportal.tools.spring;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

/** We need our own FactoryBean because Spring does not offer a way to
 * inject request scoped HttpServletResponse objects.
 * See http://forum.springsource.org/showthread.php?p=298179#post298179 */
public class HttpServletResponseFactoryBean implements FactoryBean<HttpServletResponse> {
	@Autowired 
	HttpServletRequest request;

	public HttpServletResponse getObject() throws Exception {
		return (HttpServletResponse) request.getAttribute("com.tpPortal.response");
	}

	public Class<HttpServletResponse> getObjectType() {
		return HttpServletResponse.class;
	}

	public boolean isSingleton() {
		return false;
	}
}
